<template>
  <div class="wrapper">
    <el-form
      :model="ruleForm"
      label-position="top"
      label-width="120px"
      :rules="rules"
      ref="ruleForm"
      :disabled="disable"
      :inline="true"
      class="info-form"
    >
      <div class="range_tab">保障计划</div>
      <el-form-item label="保险名称">
        <el-input v-model="ruleForm.insure_name"></el-input>
      </el-form-item>
      <el-form-item label="保险天数">
        <el-input v-model="ruleForm.insure_day"></el-input>
      </el-form-item>
      <el-form-item label="货损保障（万元）">
        <el-input v-model="ruleForm.cargo_damage"></el-input>
      </el-form-item>
      <el-form-item label="盗抢保障（万元）">
        <el-input v-model="ruleForm.robbery"></el-input>
      </el-form-item>
      <el-form-item label="意外身故/伤残保障（万元）">
        <el-input v-model="ruleForm.death"></el-input>
      </el-form-item>
      <el-form-item label="意外医疗保障（万元）">
        <el-input v-model="ruleForm.accident"></el-input>
      </el-form-item>
      <el-form-item label="猝死（万元）">
        <el-input v-model="ruleForm.sudden_death"></el-input>
      </el-form-item>
      <div class="range_tab">被投保人信息</div>
      <el-form-item label="姓名">
        <el-input v-model="ruleForm.applicant"></el-input>
      </el-form-item>
      <el-form-item label="身份证">
        <el-input v-model="ruleForm.id_card"></el-input>
      </el-form-item>
      <el-form-item label="车牌号">
        <el-input v-model="ruleForm.license_plate"></el-input>
      </el-form-item>
      <el-form-item label="手机号码">
        <el-input v-model="ruleForm.mobile_phone"></el-input>
      </el-form-item>
      <!-- <el-form-item label="承运商名称">
                <el-input v-model="ruleForm.carrier_name"></el-input>
            </el-form-item> -->
    </el-form>
    <div
      style="margin-top: 20px; text-align: center; padding-bottom: 20px"
      v-if="!disable"
    >
      <el-button @click="cancelFn">取消</el-button>
      <el-button type="primary" @click="handleSubmit">保存</el-button>
    </div>
  </div>
</template>

<script>
import { dictionanryList } from "@/page/material/common/common";
import { InsureDetail } from "@/api/app.js";
export default {
  name: "deviceOrder",
  components: {},
  props: ["mode", "id"],
  data() {
    return {
      packageData: [],
      ruleForm: {},
      rules: {
        // model_number: [
        //     { required: true, message: '请选择设备型号', trigger: 'change' }
        // ],
      },
    };
  },
  computed: {
    disable: function () {
      return this.mode === "detail";
    },
  },
  watch: {
    mode: {
      handler: function (newValue, oldValue) {
        this.handleChangeMode();
      },
      immediate: true,
    },
    id: {
      handler: function (newValue, oldValue) {
        this.handleChangeMode();
      },
      immediate: true,
    },
  },
  mounted() {
    // dictionanryList(["thermosphere", "divide_way", "Package_model"]).then(
    //     (res) => {
    //         this.packageData = res.data.list["Package_model"];
    //     }
    // );
  },
  methods: {
    handleChangeMode() {
      if (this.mode === "detail" || this.mode === "edit") {
        InsureDetail({ id: this.id }).then((res) => {
          // console.log(res, 'res-----------');
          const data = res.data.data;
          // 暂时测试
          // data.step = data.Step;
          this.ruleForm = data;
        });
      }
    },

    cancelFn() {
      this.$emit("close");
    },
    handleSubmit() {
      this.$refs["ruleForm"].validate((valid) => {
        if (!valid) return;
        if (this.ruleForm.type === "1") {
          this.ruleForm.is_expiration = "";
        }
        DeviceOrderUpdate(this.ruleForm).then((res) => {
          if (res.code === 10000) {
            this.$message({
              message: this.mode === "add" ? "创建成功" : "修改成功",
              type: "success",
            });
            // console.log(res);
            this.$emit("close", true);
          }
        });
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.wrapper {
  .range_tab {
    width: 100%;
    height: 30px;
    background: #f2f3f5;
    font-weight: bold;
    line-height: 30px;
    padding-left: 12px;
    margin-bottom: 16px;
    color: #6d6e72;
    font-size: 14px;
    box-sizing: border-box;
  }
  .info-form {
    .el-input {
      width: 200px;
    }

    .el-radio-group,
    .el-select,
    .el-cascader {
      width: 200px;
    }

    .el-textarea {
      width: 400px;
    }

    /deep/ .el-form-item {
      margin-right: 50px !important;
    }
  }
}
</style>